{% extends 'base.html' %}
{% block content %}
  <h2 class="fw-bold mb-3">{{ theme.title }} - {{ round.title }} 投票结果</h2>
  <div class="card shadow-sm p-4 mb-4">
    <table class="table align-middle mb-0">
      <thead class="table-light">
        <tr>
          <th style="width:50%">选项</th>
          <th style="width:20%">票数</th>
          <th style="width:30%">比例</th>
        </tr>
      </thead>
      <tbody>
        {% set total = results|map(attribute='count')|sum %}
        {% for r in results %}
          <tr>
            <td><span class="badge bg-primary bg-opacity-10 text-dark px-3 py-2">{{ r.label }}</span></td>
            <td><span class="fw-bold">{{ r.count }}</span></td>
            <td>
              <div class="progress" style="height:18px;">
                <div class="progress-bar bg-success" role="progressbar" style="width: {{ (100*r.count/(total or 1))|round(1) }}%;" aria-valuenow="{{ r.count }}" aria-valuemin="0" aria-valuemax="{{ total }}">
                  {{ (100*r.count/(total or 1))|round(1) }}%
                </div>
              </div>
            </td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
    <div class="mt-3 d-flex justify-content-between align-items-center">
      <span class="text-muted small">总票数：{{ total }}</span>
      <div class="dropdown">
        <button class="btn btn-sm btn-outline-primary dropdown-toggle" type="button" id="exportDropdown" data-bs-toggle="dropdown" aria-expanded="false">
          导出结果
        </button>
        <ul class="dropdown-menu" aria-labelledby="exportDropdown">
          <li><a class="dropdown-item" href="{{ url_for('export_round_result', theme_id=theme.id, round_id=round.id) }}">导出CSV</a></li>
        </ul>
      </div>
    </div>
  </div>
  <a href="{{ url_for('theme_detail', theme_id=theme.id) }}" class="btn btn-link">返回主题</a>
{% endblock %}
